/*
 * @lc app=leetcode.cn id=7 lang=cpp
 *
 * [7] 整数反转
 */
#define INT_MIN -2147483648
#define INT_MAX 2147483647
// @lc code=start
class Solution {
public:
    int reverse(int x) {
        long ans = 0;
        long y =x;
        int d = 0;
        while (y!=0)
        {
            d = y % 10;
            y = y/10;
            ans = ans*10 + d;
        }
        if (ans<INT_MIN || ans>INT_MAX)
        {
           return 0;
        }
        return ans;
        
    }
};
// @lc code=end

